package com.shujia

import java.util
import scala.collection.mutable.ListBuffer

object Demo20ListBuffer {
  def main(args: Array[String]): Unit = {


    /**
     * ListBuffer: 可变List
     */

    //创建一个空的列表
    val words = new ListBuffer[String]()

    //增加一个元素
    words += "java"
    println(words)

    //增加多个元素
    words ++= List("hadoop", "spark", "hadoop")
    println(words)

    //插入元素
    words.insert(2, "hive")
    println(words)

    //通过下标修改元素
    words.update(2, "java")
    println(words)

    //删除第一个
    words -= "hadoop"
    println(words)

    //删除元素
    words.remove(2)
    println(words)

    //清空列表
    words.clear()
    println(words)
  }

}
